package com.xl.web.service.zoom;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.xl.base.annotation.DataSource;
import com.xl.base.page.Page;
import com.xl.base.page.PageBean;
import com.xl.core.constant.Globals;
import com.xl.core.enums.SourceEnum;
import com.xl.web.dao.zoom.UserDao;
import com.xl.web.entity.zoom.SysUser;
@Service(value = "userService")
public class UserService<T extends SysUser> {
	@Resource
	private UserDao<SysUser> userDao;
	@DataSource(source = SourceEnum.TYPE_SLAVE)
	public PageBean queryPageUserInfo(SysUser user,Page page)throws Exception {
		         PageHelper.startPage(page.getPageNum() ,page.getPageSize());
				 List<SysUser> users= userDao.queryUserInfo(user);
				 PageBean  pageBean =new PageBean(users);
				 return pageBean;
	}
	@DataSource(source = SourceEnum.TYPE_SLAVE)
	public List<SysUser> queryUserInfo(SysUser user)throws Exception {
		return userDao.queryUserInfo(user);
	}
	@DataSource(source = SourceEnum.TYPE_SLAVE)
	public List<Map> queryUserByKeyWord(String keyWord)throws Exception {
		return userDao.queryUserByKeyWord(keyWord);
	}
	
	
	
	/**
	 * 保存用户添加信息
	 * @param user
	 * @throws Exception
	 */
	public void saveUser(SysUser user)throws Exception {
		userDao.saveUser(user);
	}
	/**
	 * 删除用户信息
	 * @param userId
	 */
	public void delUser(String userId)throws Exception{
		userDao.delUser(userId);
	} 
	/**
	 * 更新用户信息
	 * @param user
	 */
	public void editUser(SysUser user)throws Exception{
		userDao.editUser(user);
	} 
	
	public List<Map> queryUserByAccount(Map paraMap)throws Exception{
		List<Map> userList = userDao.queryUserByAccount(paraMap);
		return userList;
		
	}
	
	/***********************新处理逻辑开始*****************************/
	public boolean checkAccountLimit(String companyId)throws Exception{
		boolean flag = false;
		List<Map<String,String>> resultList = userDao.checkAccountLimit(companyId);
	    if(resultList!=null && resultList.size()>0){
	    	Map<String,String> tempMap = resultList.get(0);
	    	if(Globals.ACCOUNTLIMITFLAG.equals(tempMap.get("limitFlag"))){
	    		//受限制时，判断当前账户数和最大受限数值
	    		int crrentCnt = Integer.valueOf(tempMap.get("crrentCnt"));
	    		int limitCnt = Integer.valueOf(tempMap.get("limitCnt"));
	    		if(crrentCnt<limitCnt){
	    			flag = true;
	    		}
	    	}else{
	    		flag = true;
	    	}
	    }
	    return flag;
	}
	
	
	
	/***********************新处理逻辑结束*****************************/
	
	
	

}
